import { createRouter, createWebHashHistory} from 'vue-router';
import { homeMenu } from './menu/menu'
  
const routes = [
    /*
     *@description:路由重定向
     *@author: xxx
     */
    { path: "/", redirect: "/home/hpage" },
    // 登录
    {
        path: "/login",
        component: () =>
            import ("../view/login/index.vue")
    },
    
    {
        path: "/home",
        component: () => import ('../view/home/index.vue'),
        children:[
            ...homeMenu,
        ]
    },
    {
        // path:'*',
        path: '/:catchAll(.*)',
        component: () => import ('../view/404/404.vue'),
    },
   
];

const router = createRouter({
    routes,
    history: createWebHashHistory(),
    scrollBehavior() {
        return { top: 0 };
    },
});


router.beforeEach((to,from,next)=>{
    const login = window.localStorage.getItem('myv3applogin')
    //登陆状态
    if(login!=='logined'){
        //二次跳转停止执行
        if(to.path.includes("login")){
            next();
            return;
        }
        const fromPath = to.path;
        next(`/login?callBack=${fromPath}`);
        return;
    }
    next();
})

export default router;